"""

Computational Economics
02: Scripts
http://johnstachurski.net/lectures/scripts.html

    Write a program which

    * Asks the user for a sequence of integers, separated by commas
          o For example, the user enters 1, 17, -3
    * Prints out a list with the integers sorted from smallest to largest
          o In this example, prints [-3, 1, 17]
    * Hint: X.sort() sorts a list of integers from smallest to largest

"""

# prompt
prompt = 'Enter a sequence of integers (e.g. 1, 17, -3):'
input = raw_input(prompt)

# validate input
try:
    input_list = input.split(',')
    int_list = [int(i.strip()) for i in input_list]
except:
    raise Exception('invalid input, please try again.')

int_sum = sum(int_list)
int_list.sort()

print 'sum of list %s: %s' % (int_list, int_sum)


print '%s: ok' % (__file__)
